package ru.gelin.android.multiplier;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;

/**
 *  Helper to open our SQLite database.
 */
class OperationsHistoryOpenHelper extends SQLiteOpenHelper {

    /** Version of database schema */
    private static final int DATABASE_VERSION = 1;

    /** History table name */
    static final String HISTORY_TABLE = "history";

    /** ID column name */
    static final String ID_COLUMN = BaseColumns._ID;
    /** Date column name */
    static final String DATE_COLUMN = "date";
    /** Num1 column name */
    static final String NUM1_COLUMN = "num1";
    /** Num2 column name */
    static final String NUM2_COLUMN = "num2";
    /** Operation column name */
    static final String OP_COLUMN = "op";

    OperationsHistoryOpenHelper(Context context, String name) {
        super(context, name, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + HISTORY_TABLE + " (" +
                ID_COLUMN + " INTEGER PRIMARY KEY, "+
                DATE_COLUMN + " TEXT UNIQUE, " +
                NUM1_COLUMN + " REAL, " +
                NUM2_COLUMN + " REAL, " +
                OP_COLUMN + " TEXT, " +
                "CONSTRAINT unique_nums UNIQUE (" + NUM1_COLUMN + ", " + NUM2_COLUMN + ", " + OP_COLUMN + ") " +
                "ON CONFLICT REPLACE" +
                ")");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //pass
    }

}
